package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.annotation.keyWord;
import com.mall.db.domain.MemberCollection;
import com.mall.db.service.MemberCollectionService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods/mcc")
public class MemberCollectionController extends  BaseController<MemberCollection>{

    @Resource(name = "memberCollectionService")
    private MemberCollectionService cs;

    @Override
    public Map<String, Object> find(MemberCollection memberCollection) {
        PageHelper.startPage(memberCollection.getPage(), memberCollection.getLimit());
        QueryWrapper qw=new QueryWrapper();
        List<MemberCollection> list=cs.list();
        PageInfo<MemberCollection> page=new PageInfo<>(list, memberCollection.getLimit());
        return findMap(page.getList(),page.getTotal());
    }

    @RequestMapping("/seachFind")
    @keyWord
    public Map<String, Object> seachFind(MemberCollection memberCollection) {
        PageHelper.startPage(memberCollection.getPage(), memberCollection.getLimit());
        QueryWrapper qw=new QueryWrapper();
        if(!StringUtils.isEmpty(memberCollection.getPId()))
        {
            qw.eq("p_id", memberCollection.getPId());
        }
        if(!StringUtils.isEmpty(memberCollection.getPId()) && !StringUtils.isEmpty(memberCollection.getUserId())){
            qw.or();
        }
        if(!StringUtils.isEmpty(memberCollection.getUserId()))
        {
            qw.eq("user_id", memberCollection.getUserId());
        }
        List<MemberCollection> list=cs.list(qw);
        PageInfo<MemberCollection> page=new PageInfo<>(list, memberCollection.getLimit());
        return findMap(page.getList(),page.getTotal());
    }
}
